# ==== registers.py ====
class RegisterFile:
    def __init__(self):
        self.registers = [0] * 32

    def read(self, reg_num):
        if 0 <= reg_num < 32:
            return self.registers[reg_num]
        return 0

    def write(self, reg_num, value):
        if 0 < reg_num < 32:
            # 处理负数值
            if value < 0:
                value = (1 << 32) + value
            self.registers[reg_num] = value & 0xFFFFFFFF

    def reset(self):
        self.registers = [0] * 32